package com.ef.dao.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.SQLQuery;

import com.ef.dao.ClassBookingDao;
import com.ef.domain.LeadsClassEntity;
import com.ef.web.domain.CardInfo;

public class ClassBookingDaoImpl extends DaoImpl<LeadsClassEntity> implements ClassBookingDao {
 
	public List<CardInfo> bookingStudentsInfo(Date today,String classEntityType,String classType){
		
		List<CardInfo> result = new ArrayList<CardInfo>();
		SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT c.classTime,l.name,r.name as classroom,f.name as focus,l.eliteCard   FROM ef_leads l, ef_leadsclassentity e, ef_classentity c,ef_classtype t,ef_classroom r,ef_classfocus f  ");
		sql.append(" WHERE e.leads_id = l.id AND e.classentity_id = c.id AND c.classtype_id = t.id  AND r.id = c.classroom_id AND c.classfocus_id =f.id ");
		sql.append(" AND to_char(c.classdate,'yyyy-mm-dd')='").append(formater.format(today)).append("' ");
		sql.append(" AND c.type = '").append(classEntityType).append("' ");
		sql.append(" AND t.type = '").append(classType).append("' Order by c.classtime,f.name,r.name asc ");
		
		SQLQuery query = this.getSession().createSQLQuery(sql.toString());
		
		List list= query.list();
		
		for(int i=0;i<list.size();i++){
			Object[] o = (Object[])list.get(i);
			CardInfo card = new CardInfo();
			card.setTime(o[0].toString());
			card.setCourse(o[3].toString());
			card.setClassroom(o[2].toString());
			card.setClassroom(o[1].toString()+"["+o[4].toString()+"]");
			result.add(card);
		}
		
		return result;
	}
}
